<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use App\Http\Requests\StudentClassStore;
use App\Http\Requests\StudentClassEdit;
use App\Models\StudentClass;

class StudentClassController extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 班级列表
     */
    public function index()
    {
        $studentClass = new StudentClass();

        $data = $studentClass->getList();

        return response()->json($data);
    }

    /**
     * 班级添加
     * @param StudentClassStore $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function create(StudentClassStore $request)
    {
        $params = $request->validated();

        $studentClass = new StudentClass();

        $data = $studentClass->add($params);

        return response()->json($data);
    }

    /**
     * 删除班级
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function destroy($id)
    {
        $studentClass = new StudentClass();

        $data = $studentClass->del($id);

        return response()->json($data);
    }

    /**
     * 获取班级
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function show($id)
    {
        $studentClass = new StudentClass();

        $data = $studentClass->getOne($id);

        return response()->json($data);
    }

    /**
     * 修改班级
     * @param StudentEdit $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function edit(StudentClassEdit $request)
    {
        $params = $request->validated();

        $studentClass = new StudentClass();

        $data = $studentClass->edit($params);

        return response()->json($data);
    }
}
